Person.js ➔ describe(ꞌPersonꞌ)   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 156

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 156
rs 8.2857

6 Functions

Rating   Name   Duplication   Size   Complexity  
A Person.js ➔ ... ➔ it(ꞌBuildꞌ) 0 18 1
B Person.js ➔ ... ➔ it(ꞌtoJSONꞌ) 0 38 1
B Person.js ➔ ... ➔ it(ꞌCreate with JSONꞌ) 0 40 1
A Person.js ➔ ... ➔ it(ꞌconstructor does not copy instancesꞌ) 0 5 1
B Person.js ➔ ... ➔ it(ꞌCreate with mixed dataꞌ) 0 40 1
A Person.js ➔ ... ➔ it(ꞌCreate plainꞌ) 0 6 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var assert = require('chai').assert,
2
    GedcomX = require('../../');
3
4
describe('Person', function(){
5
  
6
  it('Create plain', function(){
7
    var newPerson = new GedcomX.Person(),
8
        person = GedcomX.Person();
9
    assert.instanceOf(newPerson, GedcomX.Person, 'An instance of Person is not returned when calling the constructor with new.');
10
    assert.instanceOf(person, GedcomX.Person, 'An instance of Person is not returned when calling the constructor without new.');
11
  });
12
  
13
  it('Create with JSON', function(){
14
    var person = GedcomX.Person({
15
      id: 'testPerson',
16
      private: true,
17
      gender: {
18
        type: 'http://gedcomx.org/Female'
19
      },
20
      names: [
21
        {
22
          type: 'http://gedcomx.org/BirthName',
23
          nameForms: [
24
            {
25
              fullText: 'Joanna Hopkins'
26
            }
27
          ]
28
        }  
29
      ],
30
      facts: [
31
        {
32
          type: 'http://gedcomx.org/Birth',
33
          date: {
34
            formal: '+2001-04-09'
35
          },
36
          place: {
37
            original: 'Farm house'
38
          }
39
        }  
40
      ]
41
    });
42
    assert.equal(person.getId(), 'testPerson');
43
    assert.equal(person.getPrivate(), true);
44
    assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female');
45
    assert(person.isFemale());
46
    assert(!person.isMale());
47
    assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins');
48
    var birth = person.getFactsByType('http://gedcomx.org/Birth')[0];
49
    assert.equal(birth.getDate().getFormal(), '+2001-04-09');
50
    assert.equal(birth.getPlace().getOriginal(), 'Farm house');
51
    assert.equal(person.getFactsByType('http://gedcomx.org/Death').length, 0);
52
  });
53
  
54
  it('Create with mixed data', function(){
55
    var person = GedcomX.Person({
56
      id: 'testPerson',
57
      private: true,
58
      gender: GedcomX.Gender({
59
        type: 'http://gedcomx.org/Female'
60
      }),
61
      names: [
62
        GedcomX.Name({
63
          type: 'http://gedcomx.org/BirthName',
64
          nameForms: [
65
            {
66
              fullText: 'Joanna Hopkins'
67
            }
68
          ]
69
        })
70
      ],
71
      facts: [
72
        GedcomX.Fact({
73
          type: 'http://gedcomx.org/Birth',
74
          date: GedcomX.Date({
75
            formal: '+2001-04-09'
76
          }),
77
          place: GedcomX.PlaceReference({
78
            original: 'Farm house'
79
          })
80
        })
81
      ]
82
    });
83
    assert.equal(person.getId(), 'testPerson');
84
    assert.equal(person.getPrivate(), true);
85
    assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female');
86
    assert(person.isFemale());
87
    assert(!person.isMale());
88
    assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins');
89
    var birth = person.getFactsByType('http://gedcomx.org/Birth')[0];
90
    assert.equal(birth.getDate().getFormal(), '+2001-04-09');
91
    assert.equal(birth.getPlace().getOriginal(), 'Farm house');
92
    assert.equal(person.getFactsByType('http://gedcomx.org/Death').length, 0);
93
  });
94
  
95
  it('Build', function(){
96
    var person = GedcomX.Person()
97
      .setId('testPerson')
98
      .setPrivate(true)
99
      .setGender(GedcomX.Gender().setType('http://gedcomx.org/Female'))
100
      .addName(GedcomX.Name().addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins')))
101
      .addFact(GedcomX.Fact().setType('http://gedcomx.org/Birth').setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house')));
102
    assert.equal(person.getId(), 'testPerson');
103
    assert.equal(person.getPrivate(), true);
104
    assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female');
105
    assert(person.isFemale());
106
    assert(!person.isMale());
107
    assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins');
108
    var birth = person.getFactsByType('http://gedcomx.org/Birth')[0];
109
    assert.equal(birth.getDate().getFormal(), '+2001-04-09');
110
    assert.equal(birth.getPlace().getOriginal(), 'Farm house');
111
    assert.equal(person.getFactsByType('http://gedcomx.org/Death').length, 0);
112
  });
113
  
114
  it('toJSON', function(){
115
    var data = {
116
      id: 'testPerson',
117
      private: true,
118
      gender: {
119
        type: 'http://gedcomx.org/Female'
120
      },
121
      names: [
122
        {
123
          type: 'http://gedcomx.org/BirthName',
124
          nameForms: [
125
            {
126
              fullText: 'Joanna Hopkins'
127
            }
128
          ]
129
        }  
130
      ],
131
      facts: [
132
        {
133
          type: 'http://gedcomx.org/Birth',
134
          date: {
135
            formal: '+2001-04-09'
136
          },
137
          place: {
138
            original: 'Farm house'
139
          }
140
        }  
141
      ]
142
    }, person = GedcomX.Person(data);
143
    assert.deepEqual(person.toJSON(), data);
144
    person = GedcomX.Person()
145
      .setId('testPerson')
146
      .setPrivate(true)
147
      .setGender(GedcomX.Gender().setType('http://gedcomx.org/Female'))
148
      .addName(GedcomX.Name().setType('http://gedcomx.org/BirthName').addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins')))
149
      .addFact(GedcomX.Fact().setType('http://gedcomx.org/Birth').setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house')));
150
    assert.deepEqual(person.toJSON(), data);
151
  });
152
  
153
  it('constructor does not copy instances', function(){
154
    var obj1 = GedcomX.Person();
155
    var obj2 = GedcomX.Person(obj1);
156
    assert.strictEqual(obj1, obj2);
157
  });
158
  
159
});